"use strict";
require("test").setup();

var Coroutine = require('coroutine');
var hash = require('hash');

var str_prefix = "ZG";

describe("user", function() {
    before(function() {

    });

    after(function() {
         clearDB();
    });


    it("登录", function() {
        httpPost("GET", "/v1.0/api/user/Sync", {})

        var t = "123"
        var result = httpPost("POST", "/v1.0/api/user/WebLogin", {
            "phone": "18888888888",
            "password": hash.md5(hash.md5("ZHYQ2022").digest().hex() + t).digest().hex(),
            "t": t,
        })
        assert.equal(result.code, "200");
        assert.equal(result.data.id, 2);
        assert.equal(result.data.role, "超级管理员");
        assert.equal(result.data.edited_password, true);
    });

    it("检查his", function() {
        var result = httpPost("POST", "/v1.0/api/accompanyRecord/CheckHis", {
            patient_name:"",
            adminssion_no:1123
        })
        console.error("检查his  ",result)
        assert.equal(result.code, "200");
    });

    xit("创建患陪(仅包含患者)", function() {
        var result = httpPost("POST", "/v1.0/api/accompanyRecord/Create", {
            admission_no:"0001",
            admission_time: "2022-03-17",
            patient_name:"李四",
            patient_gender:"男",
            patient_phone:"18909786578",
            patient_hash:"admin345",
            patient_attachments:JSON.stringify([111,2222,333])
        })

        // JSON.stringify([111,2222,333])
        assert.equal(result.code, "200");
        assert.equal(result.data.id, 10002);
    });

    xit("创建患陪(仅包含患者)", function() {
        var result = httpPost("POST", "/v1.0/api/accompanyRecord/Create", {
            adminssion_no:"0001",
            adminssion_time: "2022-03-17",
            patient_name:"欧尼四",
            patient_gender:"男",
            patient_phone:"18099786578",
            patient_hash:"admin345",
            patient_attachments:JSON.stringify([111,2222,333])
        })

        // JSON.stringify([111,2222,333])
        assert.equal(result.code, "200");
        assert.equal(result.data.id, 10000);
    });

    xit("患陪列表模糊查询", function() {
        var result = httpPost("POST", "/v1.0/api/accompanyRecord/List", {
            patient_name:"欧尼四",
        })
        assert.equal(result.code, "200");
        assert.equal(result.data.list.length, 1);
        assert.equal(result.data.list[0].accompany_name, "");
    });

    it("创建患陪(包含患者和陪护)", function() {
        var result = httpPost("POST", "/v1.0/api/accompanyRecord/Create", {
            adminssion_no:"0201",
            adminssion_time: "2022-03-16",
            patient_name:"李四",
            patient_gender:"男",
            patient_hash:"123456",
            patient_phone:"18909786579",
            accompany_name:"三上",
            accompany_gender:"男",
            accompany_hash: "12345",
            accompany_phone:"15645674576",
            department:"内科",
            patient_attachments:JSON.stringify([111,2222,333]),
            accompany_attachments:JSON.stringify([111,2222,333])
        })
        assert.equal(result.code, "200");
        // assert.equal(result.data.id, 10002);
    });

    it("职工列表", function () {
        var result = httpPost("POST", "/v1.0/api/user/List", {
            "page": 1,
            "limit": 10,
            // "identity":"职工",
            "role":"患陪",
            "name":"李四",
            "phone":"18909786579"
        })
        console.error("职工列表  : ",result)
        assert.equal(result.code, "200");
        // assert.equal(result.data.list.length, 5);
    });

    it("患陪详情", function() {
        var result1 = httpPost("POST", "/v1.0/api/accompanyRecord/Get", {
            id:10000,
        })
        console.error("患陪详情 ",result1)
    });


    it("患陪列表模糊查询", function() {
        var result = httpPost("POST", "/v1.0/api/accompanyRecord/List", {
        })
        console.error("患陪列表模糊查询: ",result)
        assert.equal(result.code, "200");
    });

    it("患陪详情", function() {
        var result1 = httpPost("POST", "/v1.0/api/accompanyRecord/Update", {
            patient_name:"李四",
            patient_phone:"18909786579",
            patient_hash:"123456",
            accompany_hash:"12345",
            pa_to_update_hash:"",
            ac_to_update_hash:""
        })
        console.error("患陪详情 ",result1)
    });

    it("患陪详情", function() {
        var result1 = httpPost("POST", "/v1.0/api/accompanyRecord/Get", {
            id:10000,
        })
        console.error("患陪详情1 ",result1)
    });
    xit("H5创建患陪(包含患者和陪护)", function() {
        var result = httpPost("POST", "/v1.0/api/accompanyRecord/H5Create", {
            adminssion_no:"0098",
            adminssion_time: "2022-03-17",
            patient_name:"李库卡",
            patient_gender:"男",
            patient_phone:"18909096579",
            accompany_name:"三上啊",
            accompany_gender:"男",
            accompany_phone:"18945674576",
            department:"内科",
            patient_attachments:JSON.stringify([111,2222,333]),
            accompany_attachments:JSON.stringify([111,2222,333])
        })
        assert.equal(result.code, "200");
        assert.equal(result.data.id, 10004);
    });

    xit("患陪列表", function() {
        var result = httpPost("POST", "/v1.0/api/accompanyRecord/List", {
            department:"内科"
        })
        assert.equal(result.code, "200");
        assert.equal(result.data.list.length, 2);
    });

    xit("患陪审批通过", function() {
        var result = httpPost("POST", "/v1.0/api/accompanyRecord/Pass", {
            id:10000,
        })
        assert.equal(result.code, "200");
    });

    xit("患陪列表", function() {
        var result = httpPost("POST", "/v1.0/api/accompanyRecord/List", {

        })
        assert.equal(result.data.list.length,3)
    });

    xit("患陪详情", function() {
        var result1 = httpPost("POST", "/v1.0/api/accompanyRecord/Get", {
            id:10004,
        })
        assert.equal(result1.data.getinfo.patient_name,"李库卡")
        assert.equal(result1.data.getinfo.accompany_name,"三上啊")
    });

    xit("有效时间内创建", function() {
        var result1 = httpPost("POST", "/v1.0/api/accompanyRecord/Create", {
            adminssion_no:"0401",
            adminssion_time: "2022-03-17",
            patient_name:"欧尼四",
            patient_gender:"男",
            patient_phone:"18099786578",
            patient_hash:"admin345",
            patient_attachments:JSON.stringify([111,2222,333])
        })
    });

    //吧状态置为失效
    xit("患陪状态置为失效", function() {
        var result1 = httpPost("POST", "/v1.0/api/accompanyRecord/Invalid", {
            id:10004,
        })
        assert.equal(result1.code,200)
    });
    //
    xit("患陪审批统计", function() {
        var result1 = httpPost("POST", "/v1.0/api/accompanyRecord/SearchCount", {

        })
        assert.equal(result1.code,200)
        assert.equal(result1.data.invalid_count,2)
    });

    xit("H5获取患陪审批信息", function() {
        var result1 = httpPost("POST", "/v1.0/api/accompanyRecord/H5Get", {
            id:10004,
        })
        assert.equal(result1.code,200)
        assert.equal(result1.data.getinfo.accompany_name,"三上啊")
    });

    xit("H5获取患陪审批列表", function() {
        var result1 = httpPost("POST", "/v1.0/api/accompanyRecord/H5List", {
        })
        assert.equal(result1.code,200)
        assert.equal(result1.data.list.length,4)
    });
});

require('test').run();